#include "utils.hpp"
#include "analogy.hpp"
#include "entity.hpp"

namespace mashine { namespace kb {

using namespace std;

/**
 *
 */
Analogy::Analogy() : Entity<string>("", vector<string>())
{
	// APP_LOGGER(info) << "Analogy {" << "empty" << "} instantiated";
}

/**
 *
 */
Analogy::Analogy(string name, string analog1, string analog2)
	: Entity<std::string>(name, vector<string>())
{
	params.push_back(analog1);
	params.push_back(analog2);

	// APP_LOGGER(info) << "Analogy {" << toString() << "} instantiated";
}

/**
 *
 */
Analogy::~Analogy()
{
	// APP_LOGGER(info) << "Analogy {" << toString() << "} begins to break down";
}

/**
 *
 */
Analogy::Analogy(Analogy const & analogy) : Entity<string>(analogy)
{
	// APP_LOGGER(info) << "Analogy {" << analogy.toString() << "} copied";
}

/**
 * need owerride this method in child class 
 * to correct work Entity constructor
 */
bool Analogy::validateName() const
{
	// APP_LOGGER(info) << "Analogy {" << toString() << "} name validating begin";
	
	return utils::is_analogy_name(name);
}

/**
 * need owerride this method in child class 
 * to correct work Entity constructor
 */
bool Analogy::validateParam() const
{
	// APP_LOGGER(info) << "Analogy {" << toString() << "} params validating begin";

	return params.size() == 2 && (
			(
			
				utils::is_constant_name(params[0]) && utils::is_constant_name(params[1])
			
			) || (
			
				utils::is_variable_name(params[0]) && utils::is_variable_name(params[1])
			
			));
}

string Analogy::toString() const
{
	if (name.length() == 0) return "empty";

    string ret;

    ret += name;
    ret += "(";

    vector<string>::const_iterator i;
    for (i = params.begin(); i != params.end(); i++)
    {
        ret += *i;
        ret += ", ";
    }
	
	if (params.size() != 0) 
	{
		ret.erase(ret.size() - 2, 2);
    }
    ret += ")";

    return ret;
}

}}